package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysUserbean;
import com.ruoyi.system.service.ISysUserbeanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户信息Controller
 * 
 * @author liupeng
 * @date 2025-06-06
 */
@RestController
@RequestMapping("/system/userbean")
@Api(tags ="app用户管理接口")
public class SysUserbeanController extends BaseController
{
    @Autowired
    private ISysUserbeanService sysUserbeanService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:list')")
    @GetMapping("/list")
    @ApiOperation("带分页查询用户列表")
    public TableDataInfo list(SysUserbean sysUserbean)
    {
        startPage();
        List<SysUserbean> list = sysUserbeanService.selectSysUserbeanList(sysUserbean);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:userbean:list')")
    @GetMapping("noPage/list")
    @ApiOperation("不带分页查询用户列表")
    public TableDataInfo NoPageList(SysUserbean sysUserbean)
    {
        List<SysUserbean> list = sysUserbeanService.selectSysUserbeanList(sysUserbean);
        return getDataTable(list);
    }
    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserbean sysUserbean)
    {
        List<SysUserbean> list = sysUserbeanService.selectSysUserbeanList(sysUserbean);
        ExcelUtil<SysUserbean> util = new ExcelUtil<SysUserbean>(SysUserbean.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:userbean:query')")
    @GetMapping
    @ApiOperation("获取用户信息详情")
    public AjaxResult getInfo()
    {
       Long userId=SecurityUtils.getUserId();
        return success(sysUserbeanService.selectSysUserbeanByUserId(userId));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserbean sysUserbean)
    {
        return toAjax(sysUserbeanService.insertSysUserbean(sysUserbean));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改")
    public AjaxResult edit(@RequestBody SysUserbean sysUserbean)
    {
        return toAjax(sysUserbeanService.updateSysUserbean(sysUserbean));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    @ApiOperation("删除")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysUserbeanService.deleteSysUserbeanByUserIds(userIds));
    }
}
